<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
	<title>Processing.js test of nf() (0)</title> 
	<script type="text/javascript" src="../../../processing.js"></script> 
	<script type="text/javascript" src="../../init.js"></script> 
	<style type="text/css"> 
	html, body
	{
		background: #EEE;
		font-family: Arial;
		font-size: 13px;
		margin: 0;
		padding: 0;
	}
	h1
	{
		background: #385C85;
		color: #FFF;
		padding: 10px;
		padding-left: 20px;
		margin-top: 0px;
	}
	h1 a
	{
		color: #FFF;
	}
	h2
	{
		padding-left: 20px;
	}
	p
	{
		padding-left: 20px;
		line-height: 1.3em;
	}
	p a
	{
		color: #385C85;
	}
	canvas
	{
		margin: 10px 0;
	}
	pre
	{
		margin-left: 20px;
		margin-right: 20px;
		padding: 5px;
		background: #FFF;
		border-top: 1px solid #333;
		border-bottom: 1px solid #333;
	}
	div.ref-col
	{
		float: left;
		width: 32%;
	}
	</style> 
</head> 
<body> 
	<h1>nf() test (0)</h1> 
	<h2>Tests 1 to 6</h2> 
	<p>Basic Processing examples.</p> 
	<h2>Tests 7 to 9</h2> 
	<p>Negative numbers to be formatted. Processing documentation states the number to be formatted should be greater than zero.
	<h2>Test 10</h2> 
	<p>Poor man's float truncation.</p> 
	<h2>Tests 11 and 12</h2> 
	<p><em>left</em> or <em>right</em> being zero. Processing documentation states these arguments should be greater than zero.</p> 
	<p> 
	<h2>Tests 13 and 18</h2> 
	<p>Negative values for <em>left</em> or <em>right</em>. If <em>left</em> is less than zero, it does not change anything left of the decimal. If <em>right</em> is less than zero, it transforms the float into an int.</p> 
	<p> 
	<h2>Tests 19 and 32</h2> 
	<p>Note how the way numbers are 'floored' changes if the one's digit is odd or even.</p> 
	<p> 
	<!-- copy paste your processing code below this script tag --> 
	<script id="script" type="application/processing"> 
boolean errors=false;
 
int xcoord=5;
int xoff=10;
int ycoord=35;
int yinc=15;
 
void setup() {
	size(1000,400);
	background(50);
	noLoop();
} 
 
void draw() {
	output(1,"nf(200, 10)",nf(200, 10),"0000000200");
	output(2,"nf(40, 5)",nf(40, 5),"00040");
	output(3,"nf(90, 3)",nf(90, 3),"090");
 
	output(4,"nf(200.94, 10, 4)",nf(200.94, 10, 4),"0000000200.9400");
	output(5,"nf(40.2, 5, 3)",nf(40.2, 5, 3),"00040.200");
	output(6,"nf(9.012, 3, 5)",nf(9.012, 3, 5),"009.01200");
 
	xcoord=200;
	ycoord=35;
 
	output(7,"nf(-200, 10)",nf(-200, 10),"-0000000200");
	output(8,"nf(-200.94, 10, 4)",nf(-200.94, 10, 4),"-0000000200.9400");
 
	output(9,"nf(-200, 2)",nf(-200, 2),"-200");
	output(10,"nf(-200.95, 2, 1)",nf(-200.95, 2, 1),"-200.9");
 
        output(11,"nf(-200, 0)",nf(-200, 2),"-200");
	output(12,"nf(-200.94, 2, 0)",nf(-200.94, 2, 0),"-200.94");
 
        xcoord=400;
	ycoord=35;
        
        output(13,"nf(-10, -1)",nf(-10, -1),"-10");
        output(14,"nf(-10, -3)",nf(-10, -3),"-10");
        
        output(15,"nf(-10.05, -1, -1)",nf(-10.05, -1, -1),"-10");
        output(16,"nf(-10.05, -1, -3)",nf(-10.05, -1, -3),"-10");
        
        output(17,"nf(-10.05, 3, -1)",nf(-10.05, 3, -1),"-010");
        output(18,"nf(-10.05, 3, -3)",nf(-10.05, 3, -3),"-010");
        
        xcoord=600;
	ycoord=35;
        
        output(19,"nf(-10.49, -1, -1)",nf(-10.49, -1, -1),"-10");
        output(20,"nf(-10.5, -1, -1)",nf(-10.5, -1, -1),"-10");
        
        output(21,"nf(-11.49, -1, -1)",nf(-11.49, -1, -1),"-11");
        output(22,"nf(-11.5, -1, -1)",nf(-11.5, -1, -1),"-12");
        
        output(23,"nf(-12.49, -1, -1)",nf(-12.49, -1, -1),"-12");
        output(24,"nf(-12.5, -1, -1)",nf(-12.5, -1, -1),"-12");
        
        output(25,"nf(-13.49, -1, -1)",nf(-13.49, -1, -1),"-13");
        output(26,"nf(-13.5, -1, -1)",nf(-13.5, -1, -1),"-14");
        
        xcoord=800;
	ycoord=35;
        
        output(27,"nf(-14.49, -1, -1)",nf(-14.49, -1, -1),"-14");
        output(28,"nf(-14.5, -1, -1)",nf(-14.5, -1, -1),"-14");
        
        output(28,"nf(-15.49, -1, -1)",nf(-15.49, -1, -1),"-15");
        output(29,"nf(-15.5, -1, -1)",nf(-15.5, -1, -1),"-16");
        
        output(30,"nf(-16.49, -1, -1)",nf(-16.49, -1, -1),"-16");
        output(31,"nf(-16.5, -1, -1)",nf(-16.5, -1, -1),"-16");
        
        output(31,"nf(-17.49, -1, -1)",nf(-17.49, -1, -1),"-17");
        output(32,"nf(-17.5, -1, -1)",nf(-17.5, -1, -1),"-18");
 
	String errMsg="";
	if (errors) {
		fill(255,0,0);
		errMsg="RED tests FAILED.";
	} else {
		fill(0,255,0);
		errMsg="All tests passed.";
	}
	text(errMsg,5,20);
}
 
void output(int ind,String txt,String results,String expected) {
	fill(255,255,255);
	text("["+ind+"] "+txt,xcoord,ycoord+=yinc);
	if (results.equals(expected)) {
		fill(0,255,0);
	} else {
		fill(255,0,0);
		errors=true;
	}
	text(results,xcoord+xoff,ycoord+=yinc);
	ycoord+=yinc;
}
	</script> 
	<canvas id="display"></canvas> 
	<br /> 
	<b>Test written by <a href="http://zenit.senecac.on.ca/wiki/index.php/User:Mlam19">Matthew Lam</a> 
	<pre style="border-style: dotted; border-width: 1px; background-color: #FFFFFF; padding: 2px; margin: 5px"> 


boolean errors=false;

int xcoord=5;
int xoff=10;
int ycoord=35;
int yinc=15;


void setup() {
  
    PFont font;
    font = loadFont("Eureka-90.vlw"); 
    textFont(font, 12);
    size(900,400);
    background(50);
    noLoop();
} 

void draw() {
	output(1,"nf(200, 10)",nf(200, 10),"0000000200");
	output(2,"nf(40, 5)",nf(40, 5),"00040");
	output(3,"nf(90, 3)",nf(90, 3),"090");
 
	output(4,"nf(200.94, 10, 4)",nf(200.94, 10, 4),"0000000200.9400");
	output(5,"nf(40.2, 5, 3)",nf(40.2, 5, 3),"00040.200");
	output(6,"nf(9.012, 3, 5)",nf(9.012, 3, 5),"009.01200");
 
	xcoord=200;
	ycoord=35;
 
	output(7,"nf(-200, 10)",nf(-200, 10),"-0000000200");
	output(8,"nf(-200.94, 10, 4)",nf(-200.94, 10, 4),"-0000000200.9400");
 
	output(9,"nf(-200, 2)",nf(-200, 2),"-200");
	output(10,"nf(-200.95, 2, 1)",nf(-200.95, 2, 1),"-200.9");
 
        output(11,"nf(-200, 0)",nf(-200, 2),"-200");
	output(12,"nf(-200.94, 2, 0)",nf(-200.94, 2, 0),"-200.94");
 
        xcoord=400;
	ycoord=35;
        
        output(13,"nf(-10, -1)",nf(-10, -1),"-10");
        output(14,"nf(-10, -3)",nf(-10, -3),"-10");
        
        output(15,"nf(-10.05, -1, -1)",nf(-10.05, -1, -1),"-10");
        output(16,"nf(-10.05, -1, -3)",nf(-10.05, -1, -3),"-10");
        
        output(17,"nf(-10.05, 3, -1)",nf(-10.05, 3, -1),"-010");
        output(18,"nf(-10.05, 3, -3)",nf(-10.05, 3, -3),"-010");
        
        xcoord=600;
	ycoord=35;
        
        output(19,"nf(-10.49, -1, -1)",nf(-10.49, -1, -1),"-10");
        output(20,"nf(-10.5, -1, -1)",nf(-10.5, -1, -1),"-10");
        
        output(21,"nf(-11.49, -1, -1)",nf(-11.49, -1, -1),"-11");
        output(22,"nf(-11.5, -1, -1)",nf(-11.5, -1, -1),"-12");
        
        output(23,"nf(-12.49, -1, -1)",nf(-12.49, -1, -1),"-12");
        output(24,"nf(-12.5, -1, -1)",nf(-12.5, -1, -1),"-12");
        
        output(25,"nf(-13.49, -1, -1)",nf(-13.49, -1, -1),"-13");
        output(26,"nf(-13.5, -1, -1)",nf(-13.5, -1, -1),"-14");
        
        xcoord=800;
	ycoord=35;
        
        output(27,"nf(-14.49, -1, -1)",nf(-14.49, -1, -1),"-14");
        output(28,"nf(-14.5, -1, -1)",nf(-14.5, -1, -1),"-14");
        
        output(28,"nf(-15.49, -1, -1)",nf(-15.49, -1, -1),"-15");
        output(29,"nf(-15.5, -1, -1)",nf(-15.5, -1, -1),"-16");
        
        output(30,"nf(-16.49, -1, -1)",nf(-16.49, -1, -1),"-16");
        output(31,"nf(-16.5, -1, -1)",nf(-16.5, -1, -1),"-16");
        
        output(31,"nf(-17.49, -1, -1)",nf(-17.49, -1, -1),"-17");
        output(32,"nf(-17.5, -1, -1)",nf(-17.5, -1, -1),"-18");
 
	String errMsg="";
	if (errors) {
		fill(255,0,0);
		errMsg="RED tests FAILED.";
	} else {
		fill(0,255,0);
		errMsg="All tests passed.";
	}
	text(errMsg,5,20);
}
 
void output(int ind,String txt,String results,String expected) {
	fill(255,255,255);
	text("["+ind+"] "+txt,xcoord,ycoord+=yinc);
	if (results.equals(expected)) {
		fill(0,255,0);
	} else {
		fill(255,0,0);
		errors=true;
	}
	text(results,xcoord+xoff,ycoord+=yinc);
	ycoord+=yinc;
}
	</pre> 
	<br /> 
</body> 
</html> 
 